package com.derbysoft.lowcostadapter.dswitch3.translate.impl;

import com.derbysoft.lowcostadapter.commons.dto.RoomType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by: jason
 * Date: 2012-06-26
 */
public abstract class DSwitch3Helper {

    public static Map<String, List<RoomType>> groupByRoomType(List<RoomType> roomTypes) {
        HashMap<String, List<RoomType>> result = new HashMap<String, List<RoomType>>();
        for (RoomType roomType : roomTypes) {
            String key = generatorRoomTypeKey(roomType);
            List<RoomType> roomTypesGroup = result.get(key);
            if (roomTypesGroup == null) {
                roomTypesGroup = new ArrayList<RoomType>();
                result.put(key, roomTypesGroup);
            }
            roomTypesGroup.add(roomType);
        }
        return result;
    }

    private static String generatorRoomTypeKey(RoomType roomType) {
        return String.format("%d`%d", roomType.getMealBasisID(), roomType.getPropertyRoomTypeID());
    }
}
